package cn.getech.data.development.model.vo;

import cn.getech.data.development.entity.AlarmObject;
import cn.getech.data.development.entity.AlarmReceived;
import cn.getech.data.intelligence.common.utils.Constant;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
@ApiModel(value = "告警信息")
public class AlarmVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("记录id")
    private Integer id;

    @ApiModelProperty("告警名称")
    private String name;

    @ApiModelProperty("告警对象类型,1:作业流")
    private Integer objectType;

    @ApiModelProperty("告警对象类型名")
    private String objectTypeTitle;

    @ApiModelProperty("触发条件")
    private Integer triggerCondition;

    @ApiModelProperty("免打扰时间，开始")
    private String noDisturbingStartTime;

    @ApiModelProperty("免打扰时间，结束")
    private String noDisturbingEntTime;

    @ApiModelProperty("告警方式，1：邮件，2：T信，3：电话，4：短信")
    private String alarmMode;

    private List<Integer> alarmModes;

    @ApiModelProperty("告警方式，名称")
    private String alarmModeTitle;

    @ApiModelProperty("接收人类型，1：部门，2：项目，3：本人")
    private Integer receivedType;

    @ApiModelProperty("接收人类型，名称")
    private String receivedTypeTitle;

    @ApiModelProperty("告警状态，1：启用，0：禁用")
    private Integer state;

    @ApiModelProperty("最大告警次数（不传则默认3次）")
    private Integer maxAlarmCount;

    @ApiModelProperty("最小告警间隔(min)，不传则默认30分钟")
    private Integer minAlarmInterval;

    @ApiModelProperty("接收人集合")
    private List<AlarmReceived> receivedList;
    @ApiModelProperty("接收人名称集合")
    private String receivedNames;

    @ApiModelProperty("告警对象集合")
    private List<AlarmObject> alarmObjects;
    @ApiModelProperty("告警对象名称集合")
    private String alarmObjectNames;

    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @ApiModelProperty("创建人id")
    private Integer createPer;
    @ApiModelProperty("创建人姓名")
    private String createPerName;

    /**
     * 重试发送次数，1，发送一次 2，每次重试都发送
     */
    @ApiModelProperty("重试发送次数，1，发送一次 2，每次重试都发送")
    private Integer failStatus;

    public List<Integer> getAlarmModes() {
        List<Integer> result = new ArrayList<>();
        if (StringUtils.isNotEmpty(alarmMode)) {
            String[] modes = alarmMode.split(",");
            for (String mode : modes) {
                result.add(Integer.parseInt(mode));
            }
        }
        return result;
    }

    public String getAlarmModeTitle() {
        String result = "";
        if (StringUtils.isNotEmpty(alarmMode)) {
            String[] modes = alarmMode.split(",");
            List<String> modeTitles = new ArrayList<>();
            for (String mode : modes) {
                modeTitles.add(Constant.AlarmModeEnum.ofByCode(Integer.parseInt(mode)));
            }
            return String.join(",", modeTitles);
        }
        return result;
    }

    public String getObjectTypeTitle() {
        String result = "";
        if (null != objectType) {
            return Constant.AlarmObjectTypeEnum.ofByCode(objectType);
        }
        return result;
    }

    public String getReceivedTypeTitle() {
        String result = "";
        if (null != receivedType) {
            return Constant.ReceivedTypeEnum.ofByCode(receivedType);
        }
        return result;
    }


}
